<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2012 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

defined('THINK_PATH') or exit();
/**
 * Html标签库驱动
 * @category   Extend
 * @package  Extend
 * @subpackage  Driver.Taglib
 * @author    liu21st <liu21st@gmail.com>
 */
class TagLibArticle extends TagLib
{
    // 标签定义
    protected $tags = array(
        // 标签定义： attr 属性列表 close 是否闭合（0 或者1 默认1） alias 标签别名 level 嵌套层次
        'list'  => array('attr' => 'id,name,cate', 'close' => 1),
        'clist' => array('attr' => 'id,catename,ceate_time', 'close' => 1),

    );

    /**
     * 获取文章列表标签
     * @access public
     * @param string $attr 标签属性
     * @return string
     */
    public function _list($attr, $content)
    {
        $tag = $this->parseXmlAttr($attr, 'next');
        $name = $tag['name'];

        $parse = '<?php ';
        $parse .= '$__LIST__= D(\'Article\')->getArticle();';
        $parse .= ' ?>';
        $parse .= '<volist name="__LIST__" id="' . $name . '">';
        $parse .= $content;
        $parse .= '</volist>';
        return $parse;
    }

    /**
     * 获取分类标签
     * @access public
     * @param string $attr 标签属性
     * @return string
     */
    public function _clist($attr, $content)
    {
        $tag = $this->parseXmlAttr($attr, 'next');
        $name = $tag['name'];

        $parse = '<?php ';
        $parse .= '$__CLIST__= D(\'Category\')->getCategory();';
        $parse .= ' ?>';
        $parse .= '<volist name="__CLIST__" id="' . $name . '">';
        $parse .= $content;
        $parse .= '</volist>';
        return $parse;
    }

}